package com.spring.demo.publicutil.util.encrypt;

/**
 * 异或加密 可以解密 加密的内容局限于ASCII码
 * @author youjc
 */
public class XOREncrypt {
    // 加密的盐
    public static final int salt = 55;
    /**
     * 加密
     */
    public static String encodeORdecode(String str){
        char[] chars = str.toCharArray();
        for(int i =0;i<chars.length;i++){
            chars[i] = (char)(chars[i] ^ XOREncrypt.salt);
        }
        return new String(chars);
    }

    public static void main(String[] args) {
        String str = "qwer";
        str = encodeORdecode(str);
        System.out.println("str = " + str);
        str = encodeORdecode(str);
        System.out.println("str = " + str);
    }
}
